home *** CD-ROM | disk | FTP | other *** search
/ Windows Expert / Windows Expert.iso / program / owldlgs.zip / DLGMSGBX.CPP < prev    next >
C/C++ Source or Header  |  1992-01-12  |  12KB  |  340 lines

  1. /**********************************************************************/
  2. /*                  Dlgmsgbx.cpp by Bob Bourbonnais                   */
  3. /*              released to the public domain 12/15/91                */
  4. /*            This program demonstrates a main dialog box             */
  5. /*                with a menu and butts that call all                 */
  6. /*         predefined message boxes and message beep functions.       */
  7. /**********************************************************************/
  8. #include <owl.h>
  9. #include <dialog.h>
  10. #include "dlgmsgbx.h"
  11.  
  12. class TDialog3Dialog : public TDialog    // Dialog class to add
  13.   {                     // processing for menu and
  14.   public:                 // button selections
  15.     TDialog3Dialog(LPSTR lpName)         // constructor calls
  16.       :TDialog(NULL,lpName) {};         // base class constructor
  17.  
  18.     virtual void HandleMenuAbortRetryIgnore(RTMessage Msg) // menu handlers
  19.       = [CM_FIRST + IDM_ABORTRETRYIGNORE];
  20.     virtual void HandleMenuIconAsterisk(RTMessage Msg)
  21.       = [CM_FIRST + IDM_ICONASTERISK];
  22.     virtual void HandleMenuIconExclamation(RTMessage Msg)
  23.       = [CM_FIRST + IDM_ICONEXCLAMATION];
  24.     virtual void HandleMenuIconHand(RTMessage Msg)
  25.       = [CM_FIRST + IDM_ICONHAND];
  26.     virtual void HandleMenuIconInformation(RTMessage Msg)
  27.       = [CM_FIRST + IDM_ICONINFORMATION];
  28.     virtual void HandleMenuIconQuestion(RTMessage Msg)
  29.       = [CM_FIRST + IDM_ICONQUESTION];
  30.     virtual void HandleMenuIconStop(RTMessage Msg)
  31.       = [CM_FIRST + IDM_ICONSTOP];
  32.     virtual void HandleMenuOK(RTMessage Msg)
  33.       = [CM_FIRST + IDM_OK];
  34.     virtual void HandleMenuOKCancel(RTMessage Msg)
  35.       = [CM_FIRST + IDM_OKCANCEL];
  36.     virtual void HandleMenuRetryCancel(RTMessage Msg)
  37.       = [CM_FIRST + IDM_RETRYCANCEL];
  38.     virtual void HandleMenuYesNo(RTMessage Msg)
  39.       = [CM_FIRST + IDM_YESNO];
  40.     virtual void HandleMenuYesNoCancel(RTMessage Msg)
  41.       = [CM_FIRST + IDM_YESNOCANCEL];
  42.     virtual void HandleMenuMessageBeep(RTMessage Msg)
  43.       = [CM_FIRST + IDM_MESSAGEBEEP];
  44.     virtual void HandleMenuMessageBeepLoop(RTMessage Msg)
  45.       = [CM_FIRST + IDM_MESSAGEBEEPLOOP];
  46.  
  47.     virtual void HandleButtonAbortRetryIgnore(RTMessage Msg)// button handlers
  48.       = [ID_FIRST + IDB_ABORTRETRYIGNORE];
  49.     virtual void HandleButtonIconAsterisk(RTMessage Msg)
  50.       = [ID_FIRST + IDB_ICONASTERISK];
  51.     virtual void HandleButtonIconExclamation(RTMessage Msg)
  52.       = [ID_FIRST + IDB_ICONEXCLAMATION];
  53.     virtual void HandleButtonIconHand(RTMessage Msg)
  54.       = [ID_FIRST + IDB_ICONHAND];
  55.     virtual void HandleButtonIconInformation(RTMessage Msg)
  56.       = [ID_FIRST + IDB_ICONINFORMATION];
  57.     virtual void HandleButtonIconQuestion(RTMessage Msg)
  58.       = [ID_FIRST + IDB_ICONQUESTION];
  59.     virtual void HandleButtonIconStop(RTMessage Msg)
  60.       = [ID_FIRST + IDB_ICONSTOP];
  61.     virtual void HandleButtonOK(RTMessage Msg)
  62.       = [ID_FIRST + IDB_OK];
  63.     virtual void HandleButtonOKCancel(RTMessage Msg)
  64.       = [ID_FIRST + IDB_OKCANCEL];
  65.     virtual void HandleButtonRetryCancel(RTMessage Msg)
  66.       = [ID_FIRST + IDB_RETRYCANCEL];
  67.     virtual void HandleButtonYesNo(RTMessage Msg)
  68.       = [ID_FIRST + IDB_YESNO];
  69.     virtual void HandleButtonYesNoCancel(RTMessage Msg)
  70.       = [ID_FIRST + IDB_YESNOCANCEL];
  71.     virtual void HandleButtonMessageBeep(RTMessage Msg)
  72.       = [ID_FIRST + IDB_MESSAGEBEEP];
  73.     virtual void HandleButtonMessageBeepLoop(RTMessage Msg)
  74.       = [ID_FIRST + IDB_MESSAGEBEEPLOOP];
  75.  
  76.     void DisplayStatus(int nStatus); // display status of buttons pressed
  77.                      // when within message boxes
  78.   };
  79. void TDialog3Dialog:: HandleMenuAbortRetryIgnore(RTMessage)
  80.   {
  81.   int nStatus;
  82.   nStatus = MessageBox(HWindow,"Message inside of Message Box",
  83.                "Title of Message Box",MB_ABORTRETRYIGNORE);
  84.   DisplayStatus(nStatus);
  85.   }
  86. void TDialog3Dialog:: HandleMenuIconAsterisk(RTMessage)
  87.   {
  88.   int nStatus;
  89.   nStatus = MessageBox(HWindow,"Message inside of Message Box",
  90.                "Title of Message Box",MB_ICONASTERISK);
  91.   DisplayStatus(nStatus);
  92.   }
  93. void TDialog3Dialog:: HandleMenuIconExclamation(RTMessage)
  94.   {
  95.   int nStatus;
  96.   nStatus = MessageBox(HWindow,"Message inside of Message Box",
  97.                "Title of Message Box",MB_ICONEXCLAMATION);
  98.   DisplayStatus(nStatus);
  99.   }
  100. void TDialog3Dialog:: HandleMenuIconHand(RTMessage)
  101.   {
  102.   int nStatus;
  103.   nStatus = MessageBox(HWindow,"Message inside of Message Box",
  104.                "Title of Message Box",MB_ICONHAND);
  105.   DisplayStatus(nStatus);
  106.   }
  107. void TDialog3Dialog:: HandleMenuIconInformation(RTMessage)
  108.   {
  109.   int nStatus;
  110.   nStatus = MessageBox(HWindow,"Message inside of Message Box",
  111.                "Title of Message Box",MB_ICONINFORMATION);
  112.   DisplayStatus(nStatus);
  113.   }
  114. void TDialog3Dialog:: HandleMenuIconQuestion(RTMessage)
  115.   {
  116.   int nStatus;
  117.   nStatus = MessageBox(HWindow,"Message inside of Message Box",
  118.                "Title of Message Box",MB_ICONQUESTION);
  119.   DisplayStatus(nStatus);
  120.   }
  121. void TDialog3Dialog:: HandleMenuIconStop(RTMessage)
  122.   {
  123.   int nStatus;
  124.   nStatus = MessageBox(HWindow,"Message inside of Message Box",
  125.                "Title of Message Box",MB_ICONSTOP);
  126.   DisplayStatus(nStatus);
  127.   }
  128. void TDialog3Dialog:: HandleMenuOK(RTMessage)
  129.   {
  130.   int nStatus;
  131.   nStatus = MessageBox(HWindow,"Message inside of Message Box",
  132.                "Title of Message Box",MB_OK);
  133.   DisplayStatus(nStatus);
  134.   }
  135. void TDialog3Dialog:: HandleMenuOKCancel(RTMessage)
  136.   {
  137.   int nStatus;
  138.   nStatus = MessageBox(HWindow,"Message inside of Message Box",
  139.                "Title of Message Box",MB_OKCANCEL);
  140.   DisplayStatus(nStatus);
  141.   }
  142. void TDialog3Dialog:: HandleMenuRetryCancel(RTMessage)
  143.   {
  144.   int nStatus;
  145.   nStatus = MessageBox(HWindow,"Message inside of Message Box",
  146.                "Title of Message Box",MB_RETRYCANCEL);
  147.   DisplayStatus(nStatus);
  148.   }
  149. void TDialog3Dialog:: HandleMenuYesNo(RTMessage)
  150.   {
  151.   int nStatus;
  152.   nStatus = MessageBox(HWindow,"Message inside of Message Box",
  153.                "Title of Message Box",MB_YESNO);
  154.   DisplayStatus(nStatus);
  155.   }
  156. void TDialog3Dialog:: HandleMenuYesNoCancel(RTMessage)
  157.   {
  158.   int nStatus;
  159.   nStatus = MessageBox(HWindow,"Message inside of Message Box",
  160.                "Title of Message Box",MB_YESNOCANCEL);
  161.   DisplayStatus(nStatus);
  162.   }
  163. void TDialog3Dialog:: HandleMenuMessageBeep(RTMessage)
  164.   {
  165.   MessageBeep(0);
  166.   }
  167. void TDialog3Dialog:: HandleMenuMessageBeepLoop(RTMessage)
  168.   {
  169.   int i;
  170.     for(i=0;i<100;i++)
  171.       MessageBeep(0);
  172.   }
  173.  
  174.  
  175. void TDialog3Dialog:: HandleButtonAbortRetryIgnore(RTMessage)
  176.   {
  177.   int nStatus;
  178.   nStatus = MessageBox(HWindow,"Message inside of Message Box",
  179.                "Title of Message Box",MB_ABORTRETRYIGNORE);
  180.   DisplayStatus(nStatus);
  181.   }
  182. void TDialog3Dialog:: HandleButtonIconAsterisk(RTMessage)
  183.   {
  184.   int nStatus;
  185.   nStatus = MessageBox(HWindow,"Message inside of Message Box",
  186.                "Title of Message Box",MB_ICONASTERISK);
  187.   DisplayStatus(nStatus);
  188.   }
  189. void TDialog3Dialog:: HandleButtonIconExclamation(RTMessage)
  190.   {
  191.   int nStatus;
  192.   nStatus = MessageBox(HWindow,"Message inside of Message Box",
  193.                "Title of Message Box",MB_ICONEXCLAMATION);
  194.   DisplayStatus(nStatus);
  195.   }
  196. void TDialog3Dialog:: HandleButtonIconHand(RTMessage)
  197.   {
  198.   int nStatus;
  199.   nStatus = MessageBox(HWindow,"Message inside of Message Box",
  200.                "Title of Message Box",MB_ICONHAND);
  201.   DisplayStatus(nStatus);
  202.   }
  203. void TDialog3Dialog:: HandleButtonIconInformation(RTMessage)
  204.   {
  205.   int nStatus;
  206.   nStatus = MessageBox(HWindow,"Message inside of Message Box",
  207.                "Title of Message Box",MB_ICONINFORMATION);
  208.   DisplayStatus(nStatus);
  209.   }
  210. void TDialog3Dialog:: HandleButtonIconQuestion(RTMessage)
  211.   {
  212.   int nStatus;
  213.   nStatus = MessageBox(HWindow,"Message inside of Message Box",
  214.                "Title of Message Box",MB_ICONQUESTION);
  215.   DisplayStatus(nStatus);
  216.   }
  217. void TDialog3Dialog:: HandleButtonIconStop(RTMessage)
  218.   {
  219.   int nStatus;
  220.   nStatus = MessageBox(HWindow,"Message inside of Message Box",
  221.                "Title of Message Box",MB_ICONSTOP);
  222.   DisplayStatus(nStatus);
  223.   }
  224. void TDialog3Dialog:: HandleButtonOK(RTMessage)
  225.   {
  226.   int nStatus;
  227.   nStatus = MessageBox(HWindow,"Message inside of Message Box",
  228.                "Title of Message Box",MB_OK);
  229.   DisplayStatus(nStatus);
  230.   }
  231. void TDialog3Dialog:: HandleButtonOKCancel(RTMessage)
  232.   {
  233.   int nStatus;
  234.   nStatus = MessageBox(HWindow,"Message inside of Message Box",
  235.                "Title of Message Box",MB_OKCANCEL);
  236.   DisplayStatus(nStatus);
  237.   }
  238. void TDialog3Dialog:: HandleButtonRetryCancel(RTMessage)
  239.   {
  240.   int nStatus;
  241.   nStatus = MessageBox(HWindow,"Message inside of Message Box",
  242.                "Title of Message Box",MB_RETRYCANCEL);
  243.   DisplayStatus(nStatus);
  244.   }
  245. void TDialog3Dialog:: HandleButtonYesNo(RTMessage)
  246.   {
  247.   int nStatus;
  248.   nStatus = MessageBox(HWindow,"Message inside of Message Box",
  249.                "Title of Message Box",MB_YESNO);
  250.   DisplayStatus(nStatus);
  251.   }
  252. void TDialog3Dialog:: HandleButtonYesNoCancel(RTMessage)
  253.   {
  254.   int nStatus;
  255.   nStatus = MessageBox(HWindow,"Message inside of Message Box",
  256.                "Title of Message Box",MB_YESNOCANCEL);
  257.   DisplayStatus(nStatus);
  258.   }
  259. void TDialog3Dialog:: HandleButtonMessageBeep(RTMessage)
  260.   {
  261.   MessageBeep(0);
  262.   }
  263. void TDialog3Dialog:: HandleButtonMessageBeepLoop(RTMessage)
  264.   {
  265.   int i;
  266.     for(i=0;i<100;i++)
  267.       MessageBeep(0);
  268.   }
  269.  
  270.  
  271. void TDialog3Dialog::DisplayStatus(int nStatus)
  272.   {
  273.   char szBuffer[40];
  274.   switch (nStatus)
  275.     {
  276.     case IDABORT:
  277.       wsprintf(szBuffer,"The Abort Button sent number %d",nStatus);
  278.       break;
  279.     case IDCANCEL:
  280.       wsprintf(szBuffer,"The Cancel Button sent number %d",nStatus);
  281.       break;
  282.     case IDIGNORE:
  283.       wsprintf(szBuffer,"The Ignore Button sent number %d",nStatus);
  284.       break;
  285.     case IDNO:
  286.       wsprintf(szBuffer,"The No Button sent number %d",nStatus);
  287.       break;
  288.     case IDOK:
  289.       wsprintf(szBuffer,"The OK Button sent number %d",nStatus);
  290.       break;
  291.     case IDRETRY:
  292.       wsprintf(szBuffer,"The Retry Button sent number %d",nStatus);
  293.       break;
  294.     case IDYES:
  295.       wsprintf(szBuffer,"The Yes Button sent number %d",nStatus);
  296.       break;
  297.     default:
  298.       wsprintf(szBuffer,"Out of Range Value  %d Passed",nStatus);
  299.     }
  300.     int i;
  301.     if (nStatus > 0)
  302.        MessageBox(HWindow,szBuffer,"Button Message",MB_OK);
  303.     else           //not enough memory to create message box
  304.        for (i=0;i<100;i++)MessageBeep(0);     // so beep instead
  305.   }
  306.  
  307.  
  308. /* ===================================================================== */
  309. class TDialog3App : public TApplication  // Application Class to contain
  310.   {                                      // the application
  311.   public:
  312.     TDialog3App(LPSTR lpName, HANDLE hInstance,  // constructor calls the
  313.         HANDLE hPrevInstance,            // base class constructor
  314.         LPSTR lpCmdLine, int nCmdShow)
  315.         :TApplication(lpName, hInstance,
  316.                   hPrevInstance,
  317.                   lpCmdLine, nCmdShow) {};
  318.  
  319.     virtual void InitMainWindow(); // overrides base class InitMainWindow
  320.   };
  321.  
  322. void TDialog3App::InitMainWindow() // to initialize a dialog box
  323.   {                                // as the main window
  324.   MainWindow = new TDialog3Dialog("Main_Window_Dialog");
  325.   }                                // using message processing provided
  326.                    // by derived class
  327.  
  328. /**************************************************************************/
  329. int PASCAL WinMain(HANDLE hInstance,              // main entry point from
  330.            HANDLE hPrevInstance,          // windows to this program
  331.            LPSTR lpCmdLine , int nCmdShow)
  332.   {
  333.   TDialog3App Dialog3("Dialog Tester",hInstance,  // create instance of
  334.                hPrevInstance,             // the dialog application
  335.                lpCmdLine,nCmdShow);
  336.   Dialog3.Run();                                  // run it
  337.   return (Dialog3.Status);                        // exit
  338.   }
  339. /**************************************************************************/
  340.